<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function sleep(time){
            return new Promise((res,rej)=>{
                setTimeout(res,time);
            })
        }
        async function main() {
            var str = "今天的天气真不错啊!";
            for (var i = 0; i < str.length; i++) {
                await sleep(500);//暂停500ms
                document.write(str.charAt(i));
            }
        }
        main();
    </script>
</body>

</html>